package com.rightsidetech.activity.service.impl;

import com.rightsidetech.activity.entity.ActGiftActivityStatis;
import com.rightsidetech.activity.mapper.ActGiftActivityStatisMapper;
import com.rightsidetech.activity.service.ActGiftActivityStatisService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service("actGiftActivityStatisService")
public class ActGiftActivityStatisServiceImpl implements ActGiftActivityStatisService {
    @Resource
    private ActGiftActivityStatisMapper actGiftActivityStatisMapper;
    @Override
    public void updateGiftStatistics() {
        List<ActGiftActivityStatis> list = actGiftActivityStatisMapper.selectByEndTime();
        if (!CollectionUtils.isEmpty(list)){
            for (ActGiftActivityStatis l:list){
                l.setSurplusNum(l.getTotalNum() - l.getGiftNum());
                l.setCreatedAt(new Date());
                actGiftActivityStatisMapper.insertSelective(l);
            }
        }
//       List<Long> longs = list.stream().map(ActGiftActivityStatistics::getGiftActivityId).collect(Collectors.toList());

    }
}
